package br.edu.sistemaacademico.command;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.List;

import br.edu.sistemaacademico.builder.ProfessorDAO;
import br.edu.sistemaacademico.pojo.Professor;

public class CommandProfessor extends UnicastRemoteObject implements Command,Serializable{

	ProfessorDAO professorDao = new ProfessorDAO();
	public CommandProfessor() throws RemoteException{
		super();
	}
	@Override
	public boolean alterar(Object o)  {
		try {
			Professor professor = (Professor) o;
			professorDao.alterar(professor);
			return true;
		} catch (SQLException e) { e.printStackTrace(); }
		return false;
	}

	@Override
	public Object carregaObjeto(String condicao, String tabelasAdd) {
		try {
			return professorDao.getObject(condicao, tabelasAdd);
		} catch (SQLException e) { e.printStackTrace(); }
		return null;
	}

	@Override
	public List<Object> carregar(String condicao, String tabelasAdd) {
			return professorDao.getAll(condicao, tabelasAdd,"nome");
	}

	@Override
	public boolean deletar(Object o) {
		Professor professor = (Professor) o;
		professorDao.deletar(professor);
		return true;
	}

	@Override
	public List<Object> getCampos() {
		return professorDao.getCampos();
	}

	@Override
	public boolean gravar(Object o) {
		try {
			Professor professor = (Professor) o;
			professorDao.gravar(professor);
			return true;
		} catch (SQLException e) { e.printStackTrace(); }
		return false;
	}

}
